package com.example.weight.greenSeasons.deodorization;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

import com.example.weight.R;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

public class RoleSelect extends AppCompatActivity {
    private String fName, factory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chose_role);

        Intent previousIntent = getIntent();
        fName = previousIntent.getStringExtra("name");
        factory = previousIntent.getStringExtra("factory");
        TitleBar titleBar = findViewById(R.id.role_select_titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) { finish(); }
            @Override
            public void onTitleClick(View v) {}
            @Override
            public void onRightClick(View v) {}
        });

        RadioGroup radioGroup = findViewById(R.id.role_select_group);
        radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
            RadioButton button = findViewById(checkedId);
            String role = button.getText().toString();

            Intent intent;
            if (role.equals("操作人"))
                intent = new Intent(RoleSelect.this,
                        ProductionFacilityCheck.class);
            else
                intent = new Intent(RoleSelect.this,
                        ProductionFacilityCheckInspector.class);
            intent.putExtra("name", fName);
            intent.putExtra("role", role);
            intent.putExtra("factory",factory);
            startActivity(intent);
        });
    }
}
